<!DOCTYPE html>
<!--
登录、权限、分页、搜索
-->
<?php
require 'lyb_conn.php';
session_start();
//echo $_SESSION['page_now'];
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title>显示页面</title>
        <style>
            .ly_1{color: black};
        </style>
        <style>
            .ly_2{color: blue};
        </style>
        <style>
            .ly_3{color: red};
        </style>
        <script type="text/javascript" src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
        <script type="text/javascript">
            function zd() {
                var page_appoint = document.getElementById("p1").value;
                //window.location.href = '?p=' + page_appoint;
                $.ajax({
                    url: "lyb_list.php",
                    type: 'POST',
                    dataType: 'json',
                    data: {"p": page_appoint},
                    success: function (data, textStatus, jqXHR) {
                        $("#page_banner").html(data.page_banner);
                        $("#content_list").empty();
                        //alert(data.page_list);
                        $.each(data.page_list, function () {
                            $("#content_list").append("<tr><td>" + this.user + "</td><td>" + this.title + "</td><td>" + this.content + "</td><td>" + this.add_date + "</td></tr>");
                        });
                    }
                });
            }
            function cx() {
                var lyb_session = "<?php echo $_SESSION['user'] ?>";
                if (lyb_session === "") {
                    alert('请先登录！');
                } else {
                    var cx_content = document.getElementById("p2").value;
                    //$.post('lyb_cx.php',{name:cx_content});
                    if (cx_content === "") {
                        alert('请输入查询内容！');
                    } else {
                        //window.location.href = 'lyb_search.php?kw=' + cx_content;
                        $.ajax({
                            url: "lyb_search_ajax.php",
                            type: 'POST',
                            dataType: 'json',
                            data: {"kw": cx_content},
                            success: function (data, textStatus, jqXHR) {
                                
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                alert("error"+jqXHR.status);
                            }
                        })
                    }
                }
            }
            function cz() {
                window.location.href = 'index.php';
            }
            $(document).ready(function () {
                $.ajax({
                    url: "lyb_list.php",
                    type: "post",
                    data: {"p": "1"},
                    dataType: "json",
                    success: function (data) {
                        $("#page_banner").html(data.page_banner);
                        $.each(data.page_list, function () {
                            $("#content_list").append("<tr><td>" + this.user + "</td><td>" + this.title + "</td><td>" + this.content + "</td><td>" + this.add_date + "</td></tr>");
                        });
                    }
                    ,
                    error: function (jqXHR) {
                        alert("erro" + jqXHR.status);
                    }
                });
            });
            function setpage(page) {
                //alert(page);
                $.ajax({
                    url: "lyb_list.php",
                    type: 'POST',
                    data: {"p": page},
                    dataType: "json",
                    success: function (data) {
                        //console.log(data);
                        $("#page_banner").html(data.page_banner);
                        $("#content_list").empty();
                        //alert(data.page_list);
                        $.each(data.page_list, function () {
                            $("#content_list").append("<tr><td>" + this.user + "</td><td>" + this.title + "</td><td>" + this.content + "</td><td>" + this.add_date + "</td></tr>");
                        });
                    },
                    error: function (jqXHR) {
                        alert("error" + jqXHR.status);
                    }
                });
            }
            /*
             $(document).ready(function () {
             $.ajax({
             url: "ajax_page.php",
             type: "post",
             data: {"p": "1"},
             dataType: "html",
             success: function (data) {
             $("#page_banner").html(data);
             }
             });
             })
             */
        </script>
    </head>
    <body>
        <div align="center">
            请输入用户名：
            <input type="text" style="float:center" width="20%" id="p2">
            <input type="button" style="float:center" id="cx" name="cx" value="查询" onclick="cx()">
            <input type="button" style="float:center" id="cz" name="cz" value="重置" onclick="cz()">
            <?php
            if ($_SESSION['user']) {
                echo "<a href='lyb_logout.php' style='float:right'>注销</a>";
                echo "<span style='float:right'>欢迎用户：<span class='ly_3'>" . $_SESSION['user'] . "</span></span>";
            } else {
                echo "<a href='lyb_register.php' style='float:right'>注册</a>";
                echo "<a href='lyb_login.php' style='float:right'>登录</a>";
            }
            ?>
        </div>
        <br>
        <table  id="content_list" border="1" cellspacing="0" style="width:80%" align="center">
            <tr>
                <td align="center" calss="ly_3">用户名</td>
                <td align="center" calss="ly_3">标题</td>
                <td align="center" calss="ly_3">内容</td>
                <td align="center" calss="ly_3">时间</td>
            </tr>
        </table>
        <br>
        <div align="center" id="page_banner">

        </div>
        <!--        <div align="center">
                    <input style="width:40px;" type="text" id="p1" name="p1">
                    <input type="button" id="zd" value="转到" name="zd" onclick="zd()">
                </div>-->
        <br>
        <div align="center">
            <a href="lyb_add.php" class="ly_1">继续添加</a>
        </div>

    </body>
</html>
